package org.abettor.pushbox.view;

/**
 * 自定义的按钮
 */
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.Button;

public class PushBoxButton extends Button {
	private final float BORDER = 5;
	private boolean isPressed;//按钮状态,true被按下区,false
	public PushBoxButton(Context context) {
		super(context);
	}

	public PushBoxButton(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public PushBoxButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}
	@Override
	protected void onDraw (Canvas canvas){
		super.onDraw(canvas);
		if(isPressed){
			Paint paint = new Paint();
			paint.setColor(0x7fff6600);
			int w = super.getWidth();
			int h = super.getHeight();
			canvas.drawRect(0, 0, w, h, paint);
			Paint paint1 = new Paint();
			paint1.setColor(Color.BLUE);
			paint1.setStrokeWidth(BORDER);
			canvas.drawLine(w, 0, w, h, paint1);
			canvas.drawLine(0, h, w, h, paint1);
			canvas.drawLine(0, 0, 0, h, paint1);
			canvas.drawLine(0, 0, w, 0, paint1);
		}else{
			Paint paint = new Paint();
			paint.setColor(0x00ffffff);
			int w = super.getWidth();
			int h = super.getHeight();
			canvas.drawRect(0, 0, w, h, paint);
		}
	}

	public boolean isPressed() {
		return isPressed;
	}

	public void setPressed(boolean isPressed) {
		this.isPressed = isPressed;
		//super.invalidate();
	}
	
}
